#include "comm.hpp"

// 把匿名管道改成命名管道

// client往文件里写 serve负责读，就完成了通信

int main()
{
    cout << "client begin" << endl;
    int wfd = open(NAMED_PIPE,O_WRONLY);
    cout << "client end" << endl;

    if( wfd< 0)//打开失败
        exit(1);

    // write
    char buffer[1024];
    while(true)
    {
        cout << "Please say# ";
        fgets(buffer, sizeof(buffer), stdin); // abcd\n
        if(strlen(buffer) > 0) // 至少输入一个换行
            buffer[strlen(buffer) - 1] = 0;// 去掉\n

        ssize_t n = write(wfd, buffer, strlen(buffer));
        assert(n == strlen(buffer));
        (void)n;
    }

    close(wfd);
    return 0;
}